home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / DDJMAG / DDJ9203.ZIP / 80X87.ZIP / TESTPOW.C < prev    next >
Text File  |  1991-11-09  |  2KB  |  70 lines

  1. /* testpow.c: Program to time assembler vs. C implementations of
  2.  *          pow().
  3.  * Copyright (C) 1991 by Nicholas Wilt.  All rights reserved.
  4.  */
  5.  
  6. #include "testfpu.h"
  7.  
  8. /* Number of repetitions to do */
  9. #define NUM_REPS 1000L
  10.  
  11. /* Size of array to test sumarray() on */
  12. #define ARRSIZE 2
  13.  
  14. int
  15. main(int argc, char *argv[])
  16. {
  17.   struct time beg, end;
  18.   double x;
  19.   int y;
  20.   double ret;
  21.   long i;
  22.   int j;
  23.   long dead, slow, fast;
  24.   long numreps;
  25.  
  26.   if (argc != 2) {
  27.     fprintf(stderr, "Usage: testpow #iters\n");
  28.     exit(1);
  29.   }
  30.   else {
  31.     char *sc;
  32.     numreps = strtol(argv[1], &sc, 10);
  33.   }
  34.  
  35.   printf("Calculating dead time...");
  36.   gettime(&beg);
  37.   for (i = 0; i < numreps; i++) {
  38.     x = (double) rand() / RAND_MAX;
  39.     y = rand();
  40.   }
  41.   gettime(&end);
  42.   dead = diff_time(&beg, &end);
  43.   printf("%.2f seconds\n", (float) dead/100);
  44.  
  45.   printf("Timing pow()...");
  46.   gettime(&beg);
  47.   for (i = 0; i < numreps; i++) {
  48.     x = (double) rand() / RAND_MAX;
  49.     y = rand();
  50.     ret = pow(x, y);
  51.   }
  52.   gettime(&end);
  53.   slow = diff_time(&beg, &end);
  54.   printf("%.2f seconds\n", (float) slow/100);
  55.  
  56.   printf("Timing intpow()...");
  57.   gettime(&beg);
  58.   for (i = 0; i < numreps; i++) {
  59.     x = (double) rand() / RAND_MAX;
  60.     y = rand();
  61.     ret = intpow(x, y);
  62.   }
  63.   gettime(&end);
  64.   fast = diff_time(&beg, &end);
  65.   printf("%.2f seconds\n", (float) fast/100);
  66.   printf("intpow() %d%% faster than pow()\n",
  67.     percent_diff(dead, fast, slow));
  68.   return 0;
  69. }
  70.